package cn.flying.base.web.auth.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.flying.base.common.vo.Rt;
import cn.flying.base.web.auth.domain.SysUser;
import cn.flying.base.web.auth.service.SysUserService;

/**
 * @description: 登录
 * @author: lvyong
 * @date: 2022年11月07日 22:12
 * @version: 1.0
 */
@Controller
@Validated
public class LoginController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysUserService sysUserService;

    /**
     * 登录页面
     *
     * @return
     */
    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    /**
     * 注册页面
     *
     * @return
     */
    @RequestMapping("register")
    public String register() {
        return "register";
    }

    /**
     * 注册用户
     *
     * @return
     */
    @RequestMapping("doRegister")
    @ResponseBody
    public Rt doRegister(SysUser user) {
        sysUserService.registerUser(user);
        return Rt.success("用户注册成功！");
    }

    /**
     * 忘记密码
     *
     * @return
     */
    @RequestMapping("forget")
    public String forget() {
        return "forget";
    }

    /**
     * 获取验证码
     * @return
     */
    @RequestMapping("/auth/code")
    @ResponseBody
    public Rt authCode(String phone) {
        //TODO 发送验证码
        System.out.println(phone);
        return Rt.success("验证码发送成功！");
    }

    /**
     * 校验验证码
     * @return
     */
    @RequestMapping("/auth/valid/code")
    @ResponseBody
    public Rt validCode(String cellphone, String vercode) {
        //TODO 校验验证码
        System.out.println(cellphone);
        System.out.println(vercode);
        return Rt.success("验证码校验通过！");
    }
    /**
     * 重置密码
     * @return
     */
    @RequestMapping("/resetpass")
    @ResponseBody
    public Rt resetpass(HttpServletRequest request) {
        sysUserService.restUserPassword(request);
        return Rt.success("密码重置成功！");
    }


}
